import * as fs from 'fs'
import * as path from 'path'

export const constData = {
  City: [
    {
      id: 'c5d6c396-6674-4c26-93ac-c3ee37932041',
      name: 'Dalian',
      title: '大连',
      country: 'China',
      province: 'Liaoning',
    }, {
      id: '28cf61c3-2e3f-44c7-9417-ccd1b704f4d2',
      name: 'Qingdao',
      title: '青岛',
      country: 'China',
      province: 'Shandong',
    }, {
      id: '80a9e5a4-c3ff-4704-b1e9-fbb70190b440',
      name: 'Tianjin',
      title: '天津',
      country: 'China',
      province: 'Tianjin',
    }, {
      id: 'd3a85f8b-c255-4f0e-a201-f6a71289e17e',
      name: 'Shanghai',
      title: '上海',
      country: 'China',
      province: 'Shanghai',
    }, {
      id: '332d2cdb-2d82-4748-865f-3325b61151e5',
      name: 'Brisbane',
      title: '布里斯班',
      country: 'Australia',
    }, {
      id: '0623111f-7bb7-46b3-8309-9ecc834809e2',
      name: 'Melbourne',
      title: '墨尔本',
      country: 'Australia',
    }, {
      id: 'a2ab4841-5b31-4913-bfa5-97ec942381da',
      name: 'Victoria',
      title: '维多利亚',
      country: 'Australia',
    }, {
      id: '0ffda6f6-e7c8-471b-90ab-27b0a15c4c3c',
      name: 'New South Wales',
      title: '新南威尔士',
      country: 'Australia',
    }, {
      id: '909cc394-48eb-4f1d-9d72-947c9baffe03',
      name: 'Adelaide',
      title: '阿德莱德',
      province: 'South Australia',
      country: 'Australia',
    }, {
      id: '69abc6ce-e854-4017-9b64-ecb04be5b1cf',
      name: 'Napier',
      title: '纳皮尔',
      country: 'New Zealand',
    }, {
      id: 'd5b0de23-1011-41ef-830e-d745c294a4b6',
      name: 'Hawke\'s Bay',
      title: '霍克斯湾',
      country: 'New Zealand',
    },
  ],
  Setting: [
    {
      name: 'SuperUserId',
      value: '758413b9-d43f-4426-81ed-013a32131a74',
    },
  ],
  User: [
    {
      id: '758413b9-d43f-4426-81ed-013a32131a74',
      name: 'super',
      nickName: '超级管理员',
      password: '1',
    }, {
      id: '308a5b27-2bcd-4408-8ecb-c2dc1d098b2a',
      name: 'admin',
      nickName: '管理员',
      email: 'admin@qq.com',
      phone: '13912345678',
      password: '1',
    },
  ],
}

const loadJson = () => {
  const jData = {}
  for (const name of Object.keys(constData)) {
    const fileName = path.join(__dirname, `${name.toLowerCase()}.json`)
    const exists = fs.existsSync(fileName)
    if (exists) {
      let parseData = null
      try {
        const data = fs.readFileSync(fileName, 'utf-8')
        parseData = JSON.parse(data)
        // console.log(`${fileName} parse`, parseData)
      } catch (err) {
        // tslint:disable-next-line no-console
        console.log(`${fileName} parse error`, err)
        // 未抛出异常，解析json seed data错误是非关键性异常，但需注意
      }
      jData[name] = parseData
    }
  }
  return jData
}
const jsonData = loadJson()
export { jsonData }
